package com.oweight.sagacious.auth.client.config;

import lombok.Data;
import org.springframework.beans.factory.annotation.Value;

import javax.servlet.http.HttpServletRequest;

/**
 * 服务端认证配置
 *
 * @author SAGE
 * @version v1 2019/10/16 13:42
 */

@Data
public class ServiceAuthConfig {
    private byte[] pubKeyByte;

    @Value("${auth.client.id:null}")
    private String clientId;

    @Value("${auth.client.secret}")
    private String clientSecret;

    @Value("${auth.client.token-header}")
    private String tokenHeader;

    @Value("${spring.application.name}")
    private String applicationName;

    public String getClientId() {
        return "null".equals(clientId) ? applicationName : clientId;
    }

    public String getToken(HttpServletRequest request) {
        return request.getHeader(this.getTokenHeader());
    }

}
